package com.han.elasticsearch.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName ElasticSearchConfig
 * @Description ES配置类
 * @Author hanjiale
 * @Date 2021/12/14 22:05
 * @Version 1.0
 */
@Configuration
public class ElasticSearchConfig {


    /**
     * 一个RestHighLevelClient实例需要一个REST 低级客户端构建器 来构建
     * 高级客户端将在内部创建用于基于提供的构建器执行请求的低级客户端。
     * 那个低级客户端维护一个连接池并启动一些线程，所以当你真正完成它时你应该关闭高级客户端，
     * 它会反过来关闭内部低级客户端以释放这些资源。
     * @return
     */
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("127.0.0.1",9200,"http"),
                        new HttpHost("127.0.0.1",9202,"http"),
                        new HttpHost("127.0.0.1",9203,"http")
                )
        );
        return client;
    }
}
